<template>
    <div>
        <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol"
            labelAlign="right" style="width: 500px;" class="ml-32">
            <a-spin :spinning="loading">
                <a-form-model-item :label="$t('当前') + $t('最大保存数量')">
                    <span> {{ nowCount }}</span>
                </a-form-model-item>
                <a-form-model-item :label="$t('最大保存数量') + ':'" prop="saveCount">
                    <a-input style="width: 256px;" v-model="form.saveCount"/>
                </a-form-model-item>
            </a-spin>
        </a-form-model>
            <a-button type='primary' style="margin-left: 160px;" @click="handleCreate">{{ $t('保存') }}</a-button>
    </div>
</template>

<script>

export default {
    components: {},
    data() {
        return {
            nowCount: '',
            labelCol: { span: 6 },
            wrapperCol: { span: 17 },
            form: {
                saveCount: '',
            },
            rules: {
                saveCount: [
                    { required: true, message: this.$t('只允许输入1-10的正整数'), trigger: 'blur' },
                    { pattern: /^([1-9]|10)$/, message: this.$t('只允许输入1-10的正整数'), trigger: 'blur' }
                ],

            },

            loading: false,
        };
    },
    mounted() {
        this.getCount()
    },
    methods: {
        async getCount() {
            const { data } = await this.$api.systemSettings.getImageCountApi()
            if (data.flag == 0) this.nowCount = data.count
            this.form.saveCount = this.nowCount
        },
        handleCreate() {
            this.$refs.ruleForm.validate(async valid => {
                if (valid) {
                    this.loading = true
                    const { data } = await this.$api.systemSettings.appendImageCountApi({ count: this.form.saveCount })
                    this.model(data.id) //返回模板
                    this.notice(data.id, data.params, data.flag) //通知列表显示
                    if (data.flag == '0') {
                        this.handleClose()
                        this.getCount()
                    }
                    this.loading = false
                } else {
                    return false;
                }
            });
        },
        handleClose() {
            this.$refs['ruleForm'].resetFields();
            this.isShow = false
        },

    }
}
</script>